home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE19 / PLAY.C < prev    next >
C/C++ Source or Header  |  1996-04-29  |  6KB  |  209 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "Play.h"
  5. #include <vfw.h>
  6.  
  7. #if defined (WIN32)
  8.     #define IS_WIN32 TRUE
  9. #else
  10.     #define IS_WIN32 FALSE
  11. #endif
  12.  
  13. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  14. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  15. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  16.  
  17.  
  18. HINSTANCE hInst;   // current instance
  19.  
  20. LPCTSTR lpszAppName = "MyApp";
  21. LPCTSTR lpszTitle   = "My Application"; 
  22.  
  23. // the rest of the stuff
  24. //......................
  25.  
  26. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  27.  
  28.  
  29. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  30.                       LPTSTR lpCmdLine, int nCmdShow)
  31. {
  32.    MSG      msg;
  33.    HWND     hWnd; 
  34.    WNDCLASS wc;
  35.  
  36.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  37.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  38.    wc.cbClsExtra    = 0;                      
  39.    wc.cbWndExtra    = 0;                      
  40.    wc.hInstance     = hInstance;              
  41.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  42.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  43.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  44.    wc.lpszMenuName  = lpszAppName;              
  45.    wc.lpszClassName = lpszAppName;              
  46.  
  47.    if ( IS_WIN95 )
  48.    {
  49.       if ( !RegisterWin95( &wc ) )
  50.          return( FALSE );
  51.    }
  52.    else if ( !RegisterClass( &wc ) )
  53.       return( FALSE );
  54.  
  55.    hInst = hInstance; 
  56.  
  57.    hWnd = CreateWindow( lpszAppName, 
  58.                         lpszTitle,    
  59.                         WS_OVERLAPPEDWINDOW, 
  60.                         CW_USEDEFAULT, 0, 
  61.                         CW_USEDEFAULT, 0,  
  62.                         NULL,              
  63.                         NULL,              
  64.                         hInstance,         
  65.                         NULL               
  66.                       );
  67.  
  68.    if ( !hWnd ) 
  69.       return( FALSE );
  70.  
  71.    ShowWindow( hWnd, nCmdShow ); 
  72.    UpdateWindow( hWnd );         
  73.  
  74.    while( GetMessage( &msg, NULL, 0, 0) )   
  75.    {
  76.       TranslateMessage( &msg ); 
  77.       DispatchMessage( &msg );  
  78.    }
  79.  
  80.    return( msg.wParam ); 
  81. }
  82.  
  83.  
  84. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  85. {
  86.     WNDCLASSEX wcex;
  87.  
  88.    wcex.style         = lpwc->style;
  89.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  90.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  91.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  92.    wcex.hInstance     = lpwc->hInstance;
  93.    wcex.hIcon         = lpwc->hIcon;
  94.    wcex.hCursor       = lpwc->hCursor;
  95.    wcex.hbrBackground = lpwc->hbrBackground;
  96.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  97.    wcex.lpszClassName = lpwc->lpszClassName;
  98.  
  99.    // Added elements for Windows 95.
  100.    //...............................
  101.    wcex.cbSize = sizeof(WNDCLASSEX);
  102.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  103.                             IMAGE_ICON, 16, 16,
  104.                             LR_DEFAULTCOLOR );
  105.             
  106.    return RegisterClassEx( &wcex );
  107. }
  108.  
  109. HWND hMCIWnd = NULL;           // MCIWnd window handle
  110.  
  111.  
  112. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  113. {
  114.    switch( uMsg )
  115.    {
  116.       case WM_COMMAND :
  117.               switch( LOWORD( wParam ) )
  118.               {
  119.                  case IDM_TEST:
  120.                         {
  121.                            // create MCIWnd window if one not
  122.                            // previously created
  123.                            //................................
  124.  
  125.                            if (!hMCIWnd)
  126.                            {
  127.                                hMCIWnd = MCIWndCreate(hWnd, hInst, 
  128.                                                       WS_VISIBLE | 
  129.                                                       WS_CHILD | 
  130.                                                       WS_OVERLAPPEDWINDOW |
  131.                                                       WS_BORDER |
  132.                                                       MCIWNDF_SHOWALL | 
  133.                                                       MCIWNDF_NOTIFYMODE, 
  134.                                                       NULL
  135.                                                      );
  136.                            }
  137.                            
  138.                            // play the AVI file
  139.                            //..................
  140.  
  141.                            MCIWndOpen(hMCIWnd, "Sample.avi", NULL);
  142.                            MCIWndPlay(hMCIWnd);
  143.                         }
  144.                         break;
  145.  
  146.                  case IDM_ABOUT :
  147.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  148.                         break;
  149.  
  150.                  case IDM_EXIT :
  151.                         DestroyWindow( hWnd );
  152.                         break;
  153.               }
  154.               break;
  155.  
  156.       case WM_DESTROY :
  157.               // destroy MCIWnd, if one exists
  158.               //..............................
  159.  
  160.               if (hMCIWnd)
  161.                   MCIWndDestroy(hMCIWnd);
  162.  
  163.               PostQuitMessage(0);
  164.               break;
  165.  
  166.       default :
  167.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  168.    }
  169.  
  170.    return( 0L );               
  171. }
  172.  
  173.  
  174. LRESULT CALLBACK About( HWND hDlg,           
  175.                         UINT message,        
  176.                         WPARAM wParam,       
  177.                         LPARAM lParam)
  178. {
  179.    switch (message) 
  180.    {
  181.        case WM_INITDIALOG: 
  182.                return (TRUE);
  183.  
  184.        case WM_COMMAND:                              
  185.                if (   LOWORD(wParam) == IDOK         
  186.                    || LOWORD(wParam) == IDCANCEL)    
  187.                {
  188.                        EndDialog(hDlg, TRUE);        
  189.                        return (TRUE);
  190.                }
  191.                break;
  192.    }
  193.  
  194.    return (FALSE); 
  195. }
  196.  
  197.  
  198.  
  199.                  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.